#include <vector>
#include <iostream>
using namespace std;

class Solution {
public:
    bool Find(vector<vector<int> > array,int target) {
        if(array.empty())
            return false;
        for(vector<int> v : array){
            if(v.empty() || target > v[v.size()-1] || target < v[0])
                continue;
            if(binarySearch(target,v,0,v.size()-1))
                return true;
        }
        return false;
    }
    
    bool binarySearch(int target ,const vector<int> &array,int begin, int end)
    {
        if(begin <= end)
        {
            int mid = (begin + end)/2;
            if(array[mid] < target)
                return binarySearch(target,array,mid+1,end);
            else if(array[mid] > target)
                return binarySearch(target,array,begin,mid-1);
            else
                return true;
        }
        return false;
    }
};

int main()
{
    Solution s;
    vector<vector<int>> v;
    v.push_back(vector<int>{1,3,5,7,9});
    v.push_back(vector<int>{2,4,6,8,10});
    v.push_back(vector<int>{3,9,12,15,17});
    v.push_back(vector<int>{4,13,14,18,20});
    cout<<s.Find(v,20)<<endl;
    cout<<s.Find(v,1)<<endl;
    cout<<s.Find(v,11)<<endl;


}